/*
 * @Author: lijian
 * @Date: 2022-11-15 17:01:31
 * @LastEditors: lijian
 * @LastEditTime: 2022-11-15 17:01:37
 * @Description: 
 */
function getClientIP(req) {
    let ip= req.headers['x-forwarded-for'] || // 判断是否有反向代理 IP
      req.ip  ||
      req.connection.remoteAddress || // 判断 connection 的远程 IP
      req.socket.remoteAddress || // 判断后端的 socket 的 IP
      req.connection.socket.remoteAddress || ''
    if(ip) {
      ip = ip.replace('::ffff:', '')
    }
    return ip;
  }
  
  module.exports = { getClientIP }